{% if not has_results %}
{% include 'no_results.html' %}
{% else %}

<script type='text/javascript'>
  asyncLoadManager.addCallback('map', function(){
      map.clearMarkers();
  });

  var friendsByEventId = {{friends_by_event_id_js|default:"{}"}};

  var friendsInfo = {};
{% for friend in friends %}
  friendsInfo['{{friend.user_id|escape }}'] = {
    'thumbnail_url': '{{friend.thumbnail_url|escape }}',
    'name': '{{friend.display_name|escape }}'
  };
{% endfor %}

  var searchResults = [];
{% for result in result_set.clipped_results %}
  searchResults.push(new SearchResult('{{result.url|escape}}', '{{result.url_sig|escape}}', '{{result.js_escaped_title|escape}}', '{{result.location|escape}}', '{{result.js_escaped_snippet|escape}}', new Date('{{ result.startdate|date:"r" }}'), new Date('{{ result.enddate|date:"r" }}'), '{{result.item_id|escape}}', '{{result.base_url|escape}}', {{result.interest|yesno:"1,0"}}, {{result.interest_count|default:0}}, '{{result.host_website|escape}}'));
  updateInterestInfoDisplay({{forloop.counter0}});
{% endfor %}
</script>

{% ifequal current_page "MY_EVENTS" %}
<h1 class='snippets_list_header'>Your Activities</h1>
{% endifequal %}
{% ifequal current_page "SEARCH" %}
<h1 class='snippets_list_header'>Volunteering activities
  {% if query_param_q %}
    matching '{{query_param_q|escape}}'  {# use escapejs (django 1.0) #}
  {% endif %}
</h1>
{% endifequal %}

{% for result in result_set.clipped_results %}
  <div class='snippet'>
    <div class='snippet_number'>{{ forloop.counter0|as_letter }}</div>
    <table>
    <tr>
    <td valign='top'>
    <div>
      {# TODO(paul): ESCAPE THE LOCATION FIELD AGAINST QUOTES #}
      {% if result.latlong %}
        <script type='text/javascript'>
          asyncLoadManager.addCallback('map', function() {
            var coords = '{{result.latlong}}'.split(',');
            map.addMarker(
                coords[0], coords[1], '{{ forloop.counter0|as_letter }}');
          });
        </script>
      {% endif %}

      <div class='snippet_title'>
        {# note: id comes after sig to reduce risk of truncation dropping sig #}
        <a target='_fp_target' href='/url?q={{ result.url|urlencode }}&sig={{ result.url_sig|urlencode }}&id={{ result.merge_key|urlencode }}'>{{ result.title|escape }}</a>
      </div>
      {% if result.location or result.startdate or result.interest_count %}
        <div class='snippet_sub_text'>
          {{ result.location|escape}}
          {% if result.location %}-{% endif %}
          {{ result.startdate|custom_date_format }}
          {% ifnotequal result.startdate.date result.enddate.date %}
          - {{ result.enddate|custom_date_format }}
          {% endifnotequal %}
        </div>
      {% endif %}
      {% if result.have_more %}
<div class="snippet_sub_text" style="display:inline">
      {% endif %}
      {% for entry in result.less_list %}{{ entry }}{% endfor %}
      {% if result.have_more %}
<div id="{{ result.more_id|escape}}" style="display:none;">
      {% for entry in result.more_list %}{{ entry }}{% endfor %}
<div onclick="showLessDuplicates('{{ result.more_id|escape }}')" class="more_link"> show fewer locations and times...</div>
</div>
<span id="s{{ result.more_id|escape}}" onclick="showMoreDuplicates('{{ result.more_id|escape}}')" class="more_link"> more locations and times...</span>
</div>
      {% endif %}
      <div class='snippet_text'>
        {{ result.snippet|truncate_chars:285|escape}}
      </div>

      <div class='snippet_bottom'>
        <a class='snippet_url' href='/url?q={{ result.url|urlencode }}&sig={{ result.url_sig|urlencode }}&id={{ result.merge_key|urlencode }}'>{{ result.url_short|escape }}</a>
        -
        <div class='interest_links'>
          <span style='display:{{result.interest|yesno:"none,"}};' id='like_{{forloop.counter0}}'><a href='javascript:void(0)' onclick='toggleInterest({{forloop.counter0}});return false;'>Like</a></span>

<!--          <span style='position: relative;' class='pointer'
               onclick='popupModalElement("add_to_calendar{{ forloop.counter0 }}");return false;'>
            <div id='add_to_calendar{{ forloop.counter0 }}'
                 class='add_to_calendar_floating'>
              <div class='pointer popup_text'
                   onclick='addToCalendar(this, "GOOGLE", searchResults[{{ forloop.counter0 }}])'>
                <a href='javascript:void(0)'>Add to Google Calendar</a>
              </div>
              <div class='pointer popup_text'
                   onclick='addToCalendar(this, "YAHOO", searchResults[{{ forloop.counter0 }}])'>
                <a href='javascript:void(0)'>Add to Yahoo Calendar</a>
              </div>
            </div>
            <a href='javascript:void(0);'>Add to calendar</a>
          </span>
-->
{% if moderator %}
          - <a href='/moderateblacklist?action=blacklist&key={{result.merge_key|urlencode}}'>blacklist</a>
{% endif %}
          <!-- - <span id='addthis{{ forloop.counter0 }}'>
            <a href="javascript:showShareWidget(this, searchResults[{{ forloop.counter0 }}]);void(0);"
               onmouseout="hideShareWidget()"
               onmouseover="return showShareWidget(this, searchResults[{{ forloop.counter0 }}])"
               onclick="return showShareWidget(this, searchResults[{{ forloop.counter0 }}])" >
              Share
            </a>
          </span> -->
        </div>
        <div class='snippet_interest_info' id='interest_info_{{forloop.counter0}}'></div>

      </div>

      {% if not forloop.last %}
      <div class='snippet_bottom_border'></div>
      {% endif %}
    </div>

    </td>
    </tr>
    </table>
  </div>
{% endfor %}
<div id='paginator'>
</div>
<script>
  renderPaginator(el('paginator'), {{last_result_index|default:0}}, {{display_nextpage_link|yesno:"true,false"}});
  initMap();
</script>

<script>
if (false) {
  el('debug_snippets').style.display = '';
  el('debug_snippets').innerHTML = "DEBUG INFO:<br> FP query=<a href='{{ view_url }}'>{{ view_url|escape }}</a><br> Base query= <a href='{{ result_set.query_url_encoded }}'>{{ result_set.query_url_unencoded|escape }}</a><br> num results: backend-estimated={{result_set.estimated_results|escape}}  merged-estimated={{result_set.estimated_merged_results|escape}}  backend={{result_set.num_results|escape}}   merged={{result_set.num_merged_results|escape}}";
}
</script>

{% endif %}
